from django.db import models
from django.utils import timezone


# Create your models here.
class ROOM(models.Model):
    btitle=models.CharField('名称', max_length=20)
    s_local=models.CharField('位置', max_length=20, null=True)
    s_ltext=models.TextField('备注', null=True)
    bpub_date=models.DateTimeField('日期', null=True, default=timezone.now)

    def __str__(self):
        return self.btitle

    class Meta:
        verbose_name='机房'
        verbose_name_plural='机房'


class CABINET(models.Model):
    btitle=models.CharField('名称', max_length=20, unique=True)
    S_cab_high = models.IntegerField('高度', null=True, default=42)
    s_ltext=models.TextField('备注', null=True)
    bpub_date=models.DateTimeField('日期', null=True, default=timezone.now)

    def __str__(self):
        return self.btitle

    class Meta:
        verbose_name='机柜'
        verbose_name_plural='机柜'


class DEVICETYPE(models.Model):
    btitle=models.CharField('名称', max_length=20, unique=True)
    s_ltext=models.TextField('备注', null=True)
    bpub_date=models.DateTimeField('日期', null=True, default=timezone.now)

    def __str__(self):
        return self.btitle

    class Meta:
        verbose_name='设备类型'
        verbose_name_plural='设备类型'


class SERVERS(models.Model):
    choices = (
        ("red", "red"),
        ("yellow", "yellow"),
        ("#0099FF", "blue"),
        ("green", "green"),
        ("#339999", "gray-green"),
        ("#99CC99", "default"),
        ("#888888", "gray"),
    )
    S_name = models.CharField('名称', max_length=200)
    S_type = models.ForeignKey(DEVICETYPE, verbose_name='设备类型', null=True, on_delete=models.SET_NULL, default=1)
    S_id = models.ForeignKey(ROOM, verbose_name='机房', null=True, on_delete=models.SET_NULL, default=1)
    S_cab = models.ForeignKey(CABINET, verbose_name='机柜', null=True, on_delete=models.SET_NULL)
    S_ip = models.GenericIPAddressField('IP', null=True)
    S_bottom = models.IntegerField('U位-开始', null=True)
    S_top = models.IntegerField('U位-结束', null=True)
    S_state = models.BooleanField('状态', default=True)
    S_color = models.CharField('颜色',choices=choices, default="#99CC99", max_length=200)
    S_date = models.DateTimeField('日期', null=True, default=timezone.now)
    S_des = models.TextField('备注', default="这里可以输入设备的一些描述信息.")

    class Meta:
        verbose_name='设备'
        verbose_name_plural='设备'

    def __str__(self):
        return self.S_name
